<template>
	<el-dialog title="" width="60%" visible :show-close="false" :append-to-body="true" class="wrap">
		<i class="el-icon-close close" @click="cancel" style="color: white;z-index: 99;"></i>
		<div class="bt">批量物品价格修改</div>
		<el-form label-width="100px" class="form">
			<div class="left" style="width: 30%;float: left;border-right:1px dashed #000;">
				<span style="font-size:20px;margin-left: 41%;">物品</span>
				<p style="border-bottom: 1px solid #969696;"></p>
				<ul>
					<li v-for='v in this.params'>{{v.mc}}</li>
				</ul>
			</div>
			<div class="right" style="width: 70%;float: right;">
				<span style="font-size:20px;margin-left: 45%;">价格</span>
				<el-form-item label="出售单价">
					<el-input v-model="form.jg" placeholder="请输入" class="select-block"></el-input>
				</el-form-item>
				<el-form-item label="是否上架">
					<el-tooltip placement="top" class="sx">
						<el-switch v-model="form.sfsj" active-color="#13ce66" inactive-color="#ff4949" inactive-text="是" active-text="否" active-value="N" inactive-value="Y"></el-switch>
					</el-tooltip>
				</el-form-item>
			</div>

		</el-form>
		<el-button type="danger" class="submit" @click="cancel">退出</el-button>
		<el-button type="primary" class="submit" @click="submit">保存</el-button>
	</el-dialog>
</template>
<script type="text/javascript">
	import qs from 'qs'
	export default {
		props: ['params'],
		data() {
			return {

				form: {
					jg: '',
					id: '',
					sfjs: 'Y',
				},
				// 				jg:'',
				ykcid: '',
			}
		},
		created() {
			var arr = []
			this.params.forEach(function(v, i) {
				arr.push(v.id)
			})
			this.ykcid = arr.join(",");
		},
		methods: {
			submit() {
				//检测
				this.$store.state.loading = true;
				if(!this.form.jg) {
					this.$message.warning('请填写出售单价');
					this.$store.state.loading = false;
					return;
				}
				//装载数据
				var logininfo = JSON.parse(localStorage.logininfo);
				var params2 = qs.stringify({
					ids: this.ykcid,
					jg: this.form.jg,
					sfsj: this.form.sfsj,
					yhid: logininfo.id,
					xxid: logininfo.xxid
				})
				//执行
				this.axios.post(this.$store.state.api + 'wpfx/updatepl', params2)
					.then(res => {
						if(res.data.code == 1) {
							this.$emit('close', {
								type: 'plwp',
								cancel: false
							});
							this.$store.state.loading = false;
						} else {
							this.$message.warning(res.data.msg);
							this.$store.state.loading = false;
						}
					}).catch(res => {
						this.$message.warning("服务器异常");
						this.$store.state.loading = false;
					})
			},
			cancel() {
				this.$emit('close', {
					type: 'plwp',
					cancel: true
				})
			}
		},
		computed: {
			jg() {
				let number = this.form.jcjg * this.form.ks;
				if(number <= 0) {
					return 0.00
				}
				return number;
			},
		}
	}
</script>
<style lang="less" scoped>
	.wrap {
		text-align: center;
	}
	
	.bt {
		position: absolute;
		width: 100%;
		height: 50px;
		margin: 0 auto;
		top: 0;
		left: 0;
		background: #50BFFF;
		margin-bottom: 20px;
		color: white;
		text-align: left;
		line-height: 50px;
		font-size: 17px;
		padding-left: 15px;
	}
	
	.form {
		overflow: hidden;
		text-align: left;
		margin-top: 20px;
	}
	
	.jclt {
		width: 85%;
		height: 50px;
		float: left;
		font-size: 16px;
		text-align: center;
		line-height: 50px;
		/*border-right: 1px solid #CCCCCC;*/
		cursor: pointer;
	}
	
	.input {
		display: inline-block;
	}
	
	.select-block {
		display: block;
		width: 85%;
	}
	
	.submit {
		width: 120px;
	}
	
	li {
		text-align: center;
	}
</style>